package com.dom.stor.dao.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.dom.stor.dao.entity.TStorInfo;
import com.dom.stor.dao.mapper.TStorInfoMapper;
import com.dom.stor.dao.service.ITStorInfoService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * B_仓库信息表 服务实现类
 * </p>
 *
 * @author xllei
 * @since 2018-11-17
 */
@Service
public class TStorInfoServiceImpl extends ServiceImpl<TStorInfoMapper, TStorInfo> implements ITStorInfoService {
    @Override
    public Map<Integer, String> getStorNameList(Integer memCode) {
        List<TStorInfo> storInfos = selectInfoList(memCode);
        return storInfos.stream().collect(Collectors.toMap(TStorInfo::getStorCode, entity->{ return entity.getStorAbbr();}));
    }

    private List<TStorInfo> selectInfoList(int memCode) {
        Wrapper<TStorInfo> wrapper = new EntityWrapper<>();

        return selectList(wrapper);
    }

    @Override
    public TStorInfo getStorInfo(Integer memCode, Integer storCode) {
        Wrapper<TStorInfo> wrapper = new EntityWrapper<>();
        wrapper.eq("mem_code", memCode)
                .and().eq("stor_code", storCode);
        return this.selectOne(wrapper);
    }
}
